package com.berwin.bmfb.entity;

import java.awt.*;
import java.awt.image.BufferedImage;

public class BMChar {

    private int id = 0;

    // 图集中x轴位置，原点左上角
    private int x = 0;

    // 图集中y轴位置，原点左上角
    private int y = 0;

    // 图集宽度
    private int width = 0;

    // 图集高度
    private int height = 0;

    // 显示上x轴偏移，原点左上角
    private int xOffset = 0;

    // 显示上y轴偏移，原点左上角
    private int yOffset = 0;

    // 相当于字符占的宽度
    private int xAdvance = 0;

    // 字符集
    private String letter = "";

    private int page = 0;
    private int chnl = 0;

    private Image charImage = null;

    public BMChar() {
    }

    public void setImage(BufferedImage bufferedImage) {
        if (this.x + this.y + this.width + this.height == 0)
            return;
        this.charImage = bufferedImage.getSubimage(this.x, this.y, this.width, this.height);
    }

    public Image getImage() {
        return this.charImage;
    }

    public void drawSelected(Graphics g, double scale, Color color) {
        g.setColor(color);
        g.drawRect((int) (this.x * scale), (int) (this.y * scale), (int) (this.width * scale), (int) (this.height * scale));
    }

    public void drawLetter(Graphics g, double scale, Color color) {
        g.setColor(color);
        g.setFont(new Font("Source Code Pro", Font.BOLD, 20));
        g.drawString(this.getLetter(), (int) ((this.x + this.width - 4) * scale), (int) ((this.y + this.height) * scale));
    }

    public void drawImage(Graphics g, double scale, int padding) {
        int sx = (int) (this.x * scale), sy = (int) (this.y * scale);
        g.drawImage(this.charImage, sx, sy, (int) (sx + (this.width * scale)), (int) (sy + (this.height * scale)), 0, 0, this.width, this.height, null);
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getxOffset() {
        return xOffset;
    }

    public void setxOffset(int xOffset) {
        this.xOffset = xOffset;
    }

    public int getyOffset() {
        return yOffset;
    }

    public void setyOffset(int yOffset) {
        this.yOffset = yOffset;
    }

    public int getxAdvance() {
        return xAdvance;
    }

    public void setxAdvance(int xAdvance) {
        this.xAdvance = xAdvance;
    }

    public String getLetter() {
        return letter;
    }

    public void setLetter(String letter) {
        this.letter = letter;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getChnl() {
        return chnl;
    }

    public void setChnl(int chnl) {
        this.chnl = chnl;
    }

    public boolean isWithoutDraw() {
        return this.x + this.y + this.width + this.height == 0;
    }

}
